﻿@model Himall.Model.VShopInfo
<div class="container">
    <ul class="nav nav-tabs-custom clearfix">
        <strong>微店管理</strong>
        <li><a href="./VShopManagement">微店列表</a></li>
        <li><a href="./HotVShop">热门微店管理</a></li>
        <li class="active"><a>主推微店管理</a></li>
    </ul>
    <table class="table mt20">
        <thead>
            <tr>
                <th>微店名称</th>
                <th>添加时间</th>
                <th>创建时间</th>
                <th>进店浏览量</th>
                <th>购买量</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @if (Model != null)
            {
                <tr>
                    <td>@Model.Name</td>
                    <td>@Model.VShopExtendInfo.FirstOrDefault().AddTime</td>
                    <td>@Model.CreateTime</td>
                    <td>@Model.VisitNum</td>
                    <td>@Model.buyNum</td>
                    <td>
                        <span class="btn-a">
                            <a class="good-setTopshow" onclick="ReplaceHotVShop(@Model.Id)">替换</a> <a class="good-check" onclick="DeleteTopShow(@Model.Id)">置为普通</a>
                        </span>
                    </td>
                </tr>
            }
            else
            {
                <tr><td style="text-align:center;" colspan="6"><h2 style="font-size: 18px;padding-bottom: 10px;">没有找到符合条件的数据</h2></td></tr>
            }
        </tbody>
    </table>
</div>
<div id="replace-HotVShop" style="display:none">
    <div class="choose-search" style="border-left: 1px solid #ddd;">
        <div class="form-group">
            <label class="label-inline" for="">微店名称</label>
            <input class="form-control input-ssm" type="text" id="titleKeyword">
        </div>
        &nbsp;&nbsp;&nbsp;&nbsp;<button type="button" class="btn btn-warning btn-ssm" id="searchReplaceVShopButton">搜索</button>
    </div>
    <table class="table table-bordered table-choose" id="repaceList"></table>
</div>
<script src="~/Scripts/jquery.hiMallDatagrid.js"></script>
<script type="text/javascript">
        function DeleteTopShow(id) {
            $.dialog.confirm('是否移除主推微店?', function () {
                var loading = showLoading();
                $.post('../VShop/DeleteTopShow', { vshopId: id }, function (result) {
                    loading.close();
                    if (result.success) {
                        $.dialog.tips("已将主推微店移除");
                        window.location.reload();
                    }
                    else
                        $.dialog.alert('删除失败！' + result.msg);
                })
            })
        }

        $('#searchReplaceVShopButton').click(function () {
            var vshopName = $('#titleKeyword').val();
            $("#repaceList").hiMallDatagrid('reload', { vshopName: vshopName, vshopType: 0 });
        });

        function ReplaceHotVShop(oldVShopId) {
            $.dialog({
                title: '微店替换',
                lock: true,
                width: 550,
                padding: '10px',
                id: 'replaceHotVShopDialog',
                content: $('#replace-HotVShop')[0],
            });

            //商品表格
            $("#repaceList").hiMallDatagrid({
                url: '/admin/VShop/GetVshops',
                nowrap: false,
                rownumbers: true,
                NoDataMsg: '没有找到符合条件的专题',
                border: false,
                fit: true,
                fitColumns: true,
                pagination: true,
                idField: "id",
                pageSize: 16,
                pagePosition: 'bottom',
                pageNumber: 1,
                queryParams: { vshopType: null },
                columns:
                [[
                    {
                        field: "name", title: '微店名称', align: "left"
                    },
                    {
                        field: "categoryName", title: '经营类目', align: "left"
                    },
                    {
                        field: "creatTime", title: '创建时间', align: "left"
                    },
                    {
                        field: "visiteNum", title: '进店浏览量', align: "left"
                    },
                    {
                        field: "buyNum", title: "成交量", align: "left"
                    },
                    {
                        field: "s", title: "操作", align: "center",
                        formatter: function (value, row, index) {
                            var html = "";
                            html += '<span class="btn-a"><a class="good-setTopshow">替换</a>';
                            html += '<input class="oldVShopId" type="hidden" value="' + oldVShopId + '"/><input class="newVShopId" type="hidden" value="' + row.id + '"/></span>';
                            return html;
                        },
                    }
                ]]
            });
        }

        $('#repaceList').on('click', '.good-setTopshow', function () {
            var oldId = $(this).siblings('.oldVShopId').val();
            var newId = $(this).siblings('.newVShopId').val();
            var loading = showLoading();
            $.post('../VShop/ReplaceTopShop', { oldVShopId: oldId, newVShopId: newId }, function (result) {
                loading.close();
                if (result.success) {
                    $.dialog.tips("替换成功");
                    window.location.reload();
                }
                else
                    $.dialog.alert('删除失败！' + result.msg);
            })
        })
</script>
